package com.aaa.service.sds.Impl;

import com.aaa.dao.sds.TTestRecondSdsMapper;
import com.aaa.entity.MyPage;
import com.aaa.entity.User;
import com.aaa.entity.sds.TTestRecondSds;
import com.aaa.service.sds.TTestRecondSdsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * (TTestRecondSds)表服务实现类
 *
 * @author ZEH
 * @since 2022-11-07 12:53:46
 */
@Service
public class TTestRecondSdsServiceImpl implements TTestRecondSdsService {
   @Autowired
   private TTestRecondSdsMapper tTestRecondSdsDao;

   @Override
   public PageInfo selectall(MyPage myPage, TTestRecondSds tTestRecondSds) {
      PageHelper.startPage(myPage.getPage(), myPage.getLimit());
      List<TTestRecondSds> select = tTestRecondSdsDao.selectLike(tTestRecondSds);
      PageInfo pageInfo = new PageInfo<>(select);
      return pageInfo;
   }

   /**
    * 根据id删除
    * @param id
    * @return
    */
   @Override
   public Integer delete(Integer id) {

      return tTestRecondSdsDao.deleteByPrimaryKey(id);
      //deleteByPrimaryKey 获取实体类定义的id值  进行删除
   }

   /**
    * 修改
    * @param tTestRecondSds
    * @return
    */
   @Override
   public boolean update(TTestRecondSds tTestRecondSds) {
      tTestRecondSds.setUpdatetime(new Date());
      int i = tTestRecondSdsDao.updateByPrimaryKeySelective(tTestRecondSds);
      if (i>0){
         return true;
      }else {
         return false;
      }
   }

   /**
    * 添加到回访记录
    * @param request
    * @param session
    * @return
    */
   @Override
   public boolean add(HttpServletRequest request, HttpSession session,TTestRecondSds tTestRecondSds) {
      User user = (User) session.getAttribute("user");
      String createby= user.getUsername();
      String recond = request.getParameter("recond");
      String remark = request.getParameter("remark");
      String username = request.getParameter("username");
      System.out.println("用户username = " + username);
      Integer rid= tTestRecondSdsDao.selectridbyusername(username);
      Integer pid= tTestRecondSdsDao.selectpidbyrid(username);
      Date createtime= new Date();
      tTestRecondSds.setRecond(recond);
      tTestRecondSds.setCreateby(createby);
      tTestRecondSds.setRemark(remark);
      tTestRecondSds.setRid(rid);
      tTestRecondSds.setPid(pid);
      tTestRecondSds.setCreatetime(createtime);

      boolean all=tTestRecondSdsDao.insertAll(tTestRecondSds);
      return all;
   }

   @Override
   public Integer selectidByusername(String username) {
      Integer id=tTestRecondSdsDao.selectidByusername(username);
      return id;
   }

   @Override
   public Integer selectusernameidByusername(Integer id) {
      Integer usernameid=tTestRecondSdsDao.selectusernameidByusername(id);
      return usernameid;
   }
}

